
<!DOCTYPE html>
<html>

	<head>
	<title>CAIJL's Blog</title>
	<meta charset="utf-8"/>
	<link rel="stylesheet" href="/font-awesome-4.7.0/css/font-awesome.min.css">

	<link rel="stylesheet" href="/bootstrap-3.3.7/css/bootstrap.min.css">
	<script src="/jquery-2.1.1/jquery.min.js"></script>
	<script src="/bootstrap-3.3.7/js/bootstrap.min.js"></script>

	<link rel="stylesheet" href="/css/bootstrap-slider.min.css">
	<script src="/js/bootstrap-slider.min.js"></script>
	
	<link rel="stylesheet" href="/css/main.css">
	<script src="/js/main.js"></script>
	
	<link rel="stylesheet" href="/css/cursor.css">
	<script src="/js/cursor.js"></script>
	
	
	<link rel="stylesheet" href="/css/code.css">
	<!--link rel="stylesheet" href="/css/markdown.css"-->
	
	<link rel="stylesheet" href="/css/head.css">

	<script src="/js/window.js"></script>
	<script src='//unpkg.com/valine/dist/Valine.min.js'></script>
	</head>
<body>

	<link rel="stylesheet" href="/katex/katex.min.css" crossorigin="anonymous">
	<script src="/katex/katex.min.js" crossorigin="anonymous"></script>
	<script src="/katex/contrib/mathtex-script-type.min.js" defer></script>
	<script defer src="/katex/contrib/auto-render.min.js"crossorigin="anonymous"
	    onload="renderMathInElement(document.body);"></script>
	<script>document.addEventListener("DOMContentLoaded", function() {renderMathInElement(document.body,{"delimiters":[{left: "$", right: "$", display: false}]});});</script>
	<nav class="navbar navbar-default header card" role="navigation" style="width: 100%;">
	<div class="container-fluid"> 
	<div class="navbar-header">
		<button type="button" class="navbar-toggle" data-toggle="collapse"
				data-target="#example-navbar-collapse">
			<span class="icon-bar"></span>
			<span class="icon-bar"></span>
			<span class="icon-bar"></span>
		</button>
		<a class="navbar-brand" href="/"><span><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="bold">C</mi><mi mathvariant="bold">A</mi><mi mathvariant="bold">I</mi><mi mathvariant="bold">J</mi><msup><mi mathvariant="bold">L</mi><mo mathvariant="bold" lspace="0em" rspace="0em">′</mo></msup><mi mathvariant="bold">s</mi><mi mathvariant="bold">B</mi><mi mathvariant="bold">L</mi><mi mathvariant="bold">O</mi><mi mathvariant="bold">G</mi></mrow><annotation encoding="application/x-tex">\mathbf{CAIJL'sBLOG}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height: 0.751892em; vertical-align: 0em;"></span><span class="mord"><span class="mord mathbf">C</span><span class="mord mathbf">A</span><span class="mord mathbf">I</span><span class="mord mathbf">J</span><span class="mord"><span class="mord mathbf">L</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height: 0.751892em;"><span class="" style="top: -3.063em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathbf mtight">′</span></span></span></span></span></span></span></span></span><span class="mord mathbf">s</span><span class="mord mathbf">B</span><span class="mord mathbf">L</span><span class="mord mathbf">O</span><span class="mord mathbf">G</span></span></span></span></span></span></a>
	</div>
	<div class="collapse navbar-collapse" id="example-navbar-collapse">
		<ul class="nav navbar-nav" style="background-color:#fcfcfc">
			<li><a href="/"><i class="menu-item-icon fa fa-fw fa-home"></i>首页</a></li>
			<li><a href="/archives/"><i class="menu-item-icon fa fa-fw fa-archive"></i>文章</a></li>
			<li><a href="/tags/"><i class="menu-item-icon fa fa-fw fa-tags"></i>标签</a></li>
			<li><a href="/settings/"><i class="menu-item-icon fa fa-fw fa-cogs"></i>设置</a></li>
			<!--li><a href="/about/"><i class="menu-item-icon fa fa-fw fa-user"></i>关于</a></li-->
			<li><a href="/games/"><i class="menu-item-icon fa fa-fw fa-gamepad"></i>其它</a></li>
			

		</ul>
	</div>
	</div>
	</nav>
<div class="container">
	<div style="height: 60px;"></div>
	<div class="row" >
		<div class="col-md-8">
			<div class="panel panel-default card" style="padding: 10px;position: relative;">
                <img src='/img/bg/11.png' style="width:100%"/>
				<span style="position: absolute;left:15px;bottom:15px;width:90%;"><font class="view-text" style="color:#fcfcfc;font-size:25px">题解 P2702 【[NOI2003]木棒游戏】</font><br><a href="/tags/2020/" class="tag"><span  style="background-color: rgb(52, 152, 219);">2020</span></a>&nbsp;<a href="/tags/模拟/" class="tag"><span  style="background-color: rgb(231, 76, 60);">模拟</span></a>&nbsp;<a href="/tags/题解/" class="tag"><span  style="background-color: rgb(82, 196, 26);">题解</span></a></span>
			</div>
			<div class="panel panel-default card" style="padding: 10px;" id="main">
                <h2 id="_1">一道<sub>~简单</sub>~的模拟题</h2>
<p>首先我们来看一下题面</p>
<p><img alt="严格与图2中的0~9相符" src="/img/h06x84mu.png"></p>
<!--more-->
<p><strong>???</strong> 图呢</p>
<p><img alt="黑人问号" src="/img/owt05ia3.png"></p>
<p>根据我们的生活经验，我们知道<script type="math/tex">0\to 9</script>应该是这么摆的：</p>
<p><img alt="0~9" src="/img/2uni3enp.png"></p>
<p>首先我们发现，题目中<strong>不能移动构成运算符（+、-、=）的木棒</strong> ，因此我们不管怎么移动数字的木棒，这个数的加、减和位数是不变的。我们如果把所有的数字都按照位数拆开来，以样例为例</p>
<div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span>11+77=34
</code></pre></div>
<p>变成</p>
<div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span>1*10+1*1+7*10+7*1=3*10+4*1
</code></pre></div>
<p>那么不管数字怎么变，它后面乘的多少是不会变的，因此我们可以提前处理好。然而在等号两边让我们看起来很不爽，反正符号不会变，我们可以通过<strong>初中知识</strong>移项将其全部移到一遍就ok了</p>
<div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span>1*10+1*1+7*10+7*1-3*10-4*1=0
</code></pre></div>
<p>那我们现在只需要通过更改上式中任意两个第一项使其成立就做完了</p>
<p>我们知道<script type="math/tex">n\le 1000</script>，因此我们完全可以枚举两个数，然后考虑移动火柴带来的情况，在判断是否成立</p>
<p>由于我比较懒，用了一种常数较大的<script type="math/tex">O(n^2)</script>算法，即选一个有火柴的地方，在选取一个没有火柴的地方，移动火柴，判断式子是否成立（其实这么做枚举了很多不必要的情况）</p>
<p>对于一个数字，选择用状压去描述，如果有第<script type="math/tex">i</script>根火柴，二进制下第<script type="math/tex">i</script>位就是<script type="math/tex">1</script>，反之为<script type="math/tex">0</script>
</p>
<p>当对第<script type="math/tex">i</script>根火柴进行更改时，就把数字<script type="math/tex">\oplus2^i</script>即可</p>
<p>具体实现可以参考代码</p>
<div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="  1 "></span><span class="cp">#include</span><span class="cpf">&lt;bits/stdc++.h&gt;</span><span class="cp"></span>
<span class="linenos" data-linenos="  2 "></span><span class="kt">char</span> <span class="n">ch</span><span class="p">[</span><span class="mi">2000</span><span class="p">];</span>
<span class="linenos" data-linenos="  3 "></span><span class="k">const</span> <span class="kt">int</span> <span class="n">n</span><span class="p">[</span><span class="mi">10</span><span class="p">]</span><span class="o">=</span><span class="p">{</span><span class="mb">0b1111011</span><span class="p">,</span><span class="c1">//0</span>
<span class="linenos" data-linenos="  4 "></span>                 <span class="mb">0b1001000</span><span class="p">,</span><span class="c1">//1</span>
<span class="linenos" data-linenos="  5 "></span>                 <span class="mb">0b0111101</span><span class="p">,</span><span class="c1">//2</span>
<span class="linenos" data-linenos="  6 "></span>                 <span class="mb">0b1101101</span><span class="p">,</span><span class="c1">//3</span>
<span class="linenos" data-linenos="  7 "></span>                 <span class="mb">0b1001110</span><span class="p">,</span><span class="c1">//4</span>
<span class="linenos" data-linenos="  8 "></span>                 <span class="mb">0b1100111</span><span class="p">,</span><span class="c1">//5</span>
<span class="linenos" data-linenos="  9 "></span>                 <span class="mb">0b1110111</span><span class="p">,</span><span class="c1">//6</span>
<span class="linenos" data-linenos=" 10 "></span>                 <span class="mb">0b1001001</span><span class="p">,</span><span class="c1">//7</span>
<span class="linenos" data-linenos=" 11 "></span>                 <span class="mb">0b1111111</span><span class="p">,</span><span class="c1">//8</span>
<span class="linenos" data-linenos=" 12 "></span>                 <span class="mb">0b1101111</span><span class="c1">//9</span>
<span class="linenos" data-linenos=" 13 "></span>                 <span class="p">};</span>
<span class="linenos" data-linenos=" 14 "></span><span class="k">struct</span> <span class="nc">num</span><span class="p">{</span><span class="c1">//数字 </span>
<span class="linenos" data-linenos=" 15 "></span>    <span class="kt">int</span> <span class="n">val</span><span class="p">;</span><span class="c1">//权值 </span>
<span class="linenos" data-linenos=" 16 "></span>    <span class="kt">int</span> <span class="n">des</span><span class="p">;</span><span class="c1">//描述</span>
<span class="linenos" data-linenos=" 17 "></span>    <span class="cm">/*</span>
<span class="linenos" data-linenos=" 18 "></span><span class="cm">     _   1</span>
<span class="linenos" data-linenos=" 19 "></span><span class="cm">    |_|  2 3 4</span>
<span class="linenos" data-linenos=" 20 "></span><span class="cm">    |_|  5 6 7 </span>
<span class="linenos" data-linenos=" 21 "></span><span class="cm">    */</span>
<span class="linenos" data-linenos=" 22 "></span>    <span class="cm">/*                  7 6 5 4 3 2 1</span>
<span class="linenos" data-linenos=" 23 "></span><span class="cm">    1  4 7              1 0 0 1 0 0 0</span>
<span class="linenos" data-linenos=" 24 "></span><span class="cm">    2  1 3 4 5 6        0 1 1 1 1 0 1</span>
<span class="linenos" data-linenos=" 25 "></span><span class="cm">    3  1 3 4 6 7        1 1 0 1 1 0 1</span>
<span class="linenos" data-linenos=" 26 "></span><span class="cm">    4  2 3 4 7          1 0 0 1 1 1 0</span>
<span class="linenos" data-linenos=" 27 "></span><span class="cm">    5  1 2 3 6 7        1 1 0 0 1 1 1</span>
<span class="linenos" data-linenos=" 28 "></span><span class="cm">    6  1 2 3 5 6 7      1 1 1 0 1 1 1</span>
<span class="linenos" data-linenos=" 29 "></span><span class="cm">    7  1 4 7            1 0 0 1 0 0 1</span>
<span class="linenos" data-linenos=" 30 "></span><span class="cm">    8  1 2 3 4 5 6 7    1 1 1 1 1 1 1</span>
<span class="linenos" data-linenos=" 31 "></span><span class="cm">    9  1 2 3 4 6 7      1 1 0 1 1 1 1</span>
<span class="linenos" data-linenos=" 32 "></span><span class="cm">    0  1 2 4 5 6 7      1 1 1 1 0 1 1</span>
<span class="linenos" data-linenos=" 33 "></span><span class="cm">    */</span>
<span class="linenos" data-linenos=" 34 "></span>    <span class="kt">bool</span> <span class="nf">check</span><span class="p">(){</span><span class="c1">//检验是否合法 </span>
<span class="linenos" data-linenos=" 35 "></span>        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="mi">10</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="linenos" data-linenos=" 36 "></span>            <span class="k">if</span><span class="p">(</span><span class="n">val</span><span class="o">==</span><span class="n">n</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
<span class="linenos" data-linenos=" 37 "></span>                <span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
<span class="linenos" data-linenos=" 38 "></span>        <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
<span class="linenos" data-linenos=" 39 "></span>    <span class="p">}</span>
<span class="linenos" data-linenos=" 40 "></span>    <span class="kt">bool</span> <span class="nf">check</span><span class="p">(</span><span class="kt">int</span> <span class="n">w</span><span class="p">){</span><span class="c1">//检验第w根是否存在 </span>
<span class="linenos" data-linenos=" 41 "></span>        <span class="k">if</span><span class="p">(</span><span class="n">val</span><span class="o">&gt;&gt;</span><span class="n">w</span><span class="o">&amp;</span><span class="mi">1</span><span class="o">!=</span><span class="mi">0</span><span class="p">)</span><span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
<span class="linenos" data-linenos=" 42 "></span>        <span class="k">return</span> <span class="nb">false</span><span class="p">;</span> 
<span class="linenos" data-linenos=" 43 "></span>    <span class="p">}</span>
<span class="linenos" data-linenos=" 44 "></span>    <span class="kt">bool</span> <span class="nf">change</span><span class="p">(</span><span class="kt">int</span> <span class="n">w</span><span class="p">){</span><span class="c1">//更改w根的位置 </span>
<span class="linenos" data-linenos=" 45 "></span>        <span class="n">val</span><span class="o">^=</span><span class="p">(</span><span class="mi">1</span><span class="o">&lt;&lt;</span><span class="n">w</span><span class="p">);</span>
<span class="linenos" data-linenos=" 46 "></span>    <span class="p">}</span>
<span class="linenos" data-linenos=" 47 "></span>    <span class="kt">int</span> <span class="nf">get</span><span class="p">(){</span>
<span class="linenos" data-linenos=" 48 "></span>        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="mi">10</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="linenos" data-linenos=" 49 "></span>            <span class="k">if</span><span class="p">(</span><span class="n">val</span><span class="o">==</span><span class="n">n</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
<span class="linenos" data-linenos=" 50 "></span>                <span class="k">return</span> <span class="n">i</span><span class="p">;</span>
<span class="linenos" data-linenos=" 51 "></span>    <span class="p">}</span>
<span class="linenos" data-linenos=" 52 "></span>    <span class="n">num</span><span class="p">(</span><span class="kt">int</span> <span class="n">_N</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="kt">int</span> <span class="n">Wi</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="kt">int</span> <span class="n">type</span><span class="o">=</span><span class="mi">0</span><span class="p">){</span><span class="c1">//_N表示数值  Wi表示位置 </span>
<span class="linenos" data-linenos=" 53 "></span>        <span class="n">val</span><span class="o">=</span><span class="n">n</span><span class="p">[</span><span class="n">_N</span><span class="p">];</span>
<span class="linenos" data-linenos=" 54 "></span>        <span class="n">des</span><span class="o">=</span><span class="n">type</span><span class="o">*</span><span class="n">pow</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="n">Wi</span><span class="p">);</span> 
<span class="linenos" data-linenos=" 55 "></span>    <span class="p">}</span>
<span class="linenos" data-linenos=" 56 "></span><span class="p">}</span><span class="n">a</span><span class="p">[</span><span class="mi">2000</span><span class="p">];</span>
<span class="linenos" data-linenos=" 57 "></span><span class="kt">bool</span> <span class="nf">check</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span><span class="n">t</span><span class="p">,</span><span class="kt">int</span> <span class="n">L</span><span class="p">){</span><span class="c1">//检查 </span>
<span class="linenos" data-linenos=" 58 "></span>    <span class="kt">int</span> <span class="n">num</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="linenos" data-linenos=" 59 "></span>    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;=</span><span class="n">L</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
<span class="linenos" data-linenos=" 60 "></span>        <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="n">t</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">check</span><span class="p">())</span><span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
<span class="linenos" data-linenos=" 61 "></span>        <span class="n">num</span><span class="o">+=</span><span class="n">t</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">des</span><span class="o">*</span><span class="n">t</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">get</span><span class="p">();</span>
<span class="linenos" data-linenos=" 62 "></span>    <span class="p">}</span>
<span class="linenos" data-linenos=" 63 "></span>    <span class="k">return</span> <span class="n">num</span><span class="o">==</span><span class="mi">0</span><span class="p">;</span>
<span class="linenos" data-linenos=" 64 "></span><span class="p">}</span>
<span class="linenos" data-linenos=" 65 "></span><span class="kt">int</span> <span class="n">tot</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="linenos" data-linenos=" 66 "></span><span class="kt">signed</span> <span class="nf">main</span><span class="p">(){</span>
<span class="linenos" data-linenos=" 67 "></span>    <span class="c1">//freopen(&quot;t.in&quot;,&quot;r&quot;,stdin);</span>
<span class="linenos" data-linenos=" 68 "></span>    <span class="kt">int</span> <span class="n">len</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">eq</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span>
<span class="linenos" data-linenos=" 69 "></span>    <span class="k">while</span><span class="p">(</span><span class="nb">true</span><span class="p">){</span>
<span class="linenos" data-linenos=" 70 "></span>        <span class="n">ch</span><span class="p">[</span><span class="o">++</span><span class="n">len</span><span class="p">]</span><span class="o">=</span><span class="n">getchar</span><span class="p">();</span>
<span class="linenos" data-linenos=" 71 "></span>        <span class="k">if</span><span class="p">(</span><span class="n">ch</span><span class="p">[</span><span class="n">len</span><span class="p">]</span><span class="o">==</span><span class="sc">&#39;#&#39;</span><span class="p">)</span><span class="k">break</span><span class="p">;</span>
<span class="linenos" data-linenos=" 72 "></span>    <span class="p">}</span>
<span class="linenos" data-linenos=" 73 "></span>    <span class="k">while</span><span class="p">(</span><span class="n">ch</span><span class="p">[</span><span class="n">eq</span><span class="p">]</span><span class="o">!=</span><span class="sc">&#39;=&#39;</span><span class="p">)</span><span class="n">eq</span><span class="o">++</span><span class="p">;</span>
<span class="linenos" data-linenos=" 74 "></span>    <span class="c1">//分别处理等号前后</span>
<span class="linenos" data-linenos=" 75 "></span>    <span class="c1">//把右边的等价到左边</span>
<span class="linenos" data-linenos=" 76 "></span>    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="n">len</span><span class="mi">-1</span><span class="p">,</span><span class="n">j</span><span class="p">;</span><span class="n">i</span><span class="o">&gt;</span><span class="n">eq</span><span class="p">;</span><span class="n">i</span><span class="o">=</span><span class="n">j</span><span class="mi">-1</span><span class="p">){</span>
<span class="linenos" data-linenos=" 77 "></span>        <span class="n">j</span><span class="o">=</span><span class="n">i</span><span class="p">;</span>
<span class="linenos" data-linenos=" 78 "></span>        <span class="k">while</span><span class="p">(</span><span class="n">j</span><span class="mi">-1</span><span class="o">&gt;</span><span class="mi">0</span><span class="o">&amp;&amp;</span><span class="n">isdigit</span><span class="p">(</span><span class="n">ch</span><span class="p">[</span><span class="n">j</span><span class="mi">-1</span><span class="p">]))</span><span class="n">j</span><span class="o">--</span><span class="p">;</span>
<span class="linenos" data-linenos=" 79 "></span>        <span class="kt">int</span> <span class="n">type</span><span class="o">=</span><span class="mi">-1</span><span class="p">;</span>
<span class="linenos" data-linenos=" 80 "></span>        <span class="k">if</span><span class="p">(</span><span class="n">ch</span><span class="p">[</span><span class="n">j</span><span class="mi">-1</span><span class="p">]</span><span class="o">==</span><span class="sc">&#39;-&#39;</span><span class="p">)</span><span class="n">type</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span>
<span class="linenos" data-linenos=" 81 "></span>        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">w</span><span class="o">=</span><span class="n">i</span><span class="p">;</span><span class="n">w</span><span class="o">&gt;=</span><span class="n">j</span><span class="p">;</span><span class="n">w</span><span class="o">--</span><span class="p">)</span>
<span class="linenos" data-linenos=" 82 "></span>            <span class="n">a</span><span class="p">[</span><span class="o">++</span><span class="n">tot</span><span class="p">]</span><span class="o">=</span><span class="n">num</span><span class="p">(</span><span class="n">ch</span><span class="p">[</span><span class="n">w</span><span class="p">]</span><span class="o">-</span><span class="sc">&#39;0&#39;</span><span class="p">,</span><span class="n">i</span><span class="o">-</span><span class="n">w</span><span class="p">,</span><span class="n">type</span><span class="p">);</span>
<span class="linenos" data-linenos=" 83 "></span>        <span class="k">if</span><span class="p">(</span><span class="n">ch</span><span class="p">[</span><span class="n">j</span><span class="mi">-1</span><span class="p">]</span><span class="o">==</span><span class="sc">&#39;+&#39;</span><span class="o">||</span><span class="n">ch</span><span class="p">[</span><span class="n">j</span><span class="mi">-1</span><span class="p">]</span><span class="o">==</span><span class="sc">&#39;-&#39;</span><span class="p">)</span><span class="n">j</span><span class="o">--</span><span class="p">;</span>
<span class="linenos" data-linenos=" 84 "></span>    <span class="p">}</span> 
<span class="linenos" data-linenos=" 85 "></span>    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="n">eq</span><span class="mi">-1</span><span class="p">,</span><span class="n">j</span><span class="p">;</span><span class="n">i</span><span class="o">&gt;=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o">=</span><span class="n">j</span><span class="mi">-1</span><span class="p">){</span>
<span class="linenos" data-linenos=" 86 "></span>        <span class="n">j</span><span class="o">=</span><span class="n">i</span><span class="p">;</span>
<span class="linenos" data-linenos=" 87 "></span>        <span class="k">while</span><span class="p">(</span><span class="n">j</span><span class="mi">-1</span><span class="o">&gt;</span><span class="mi">0</span><span class="o">&amp;&amp;</span><span class="n">isdigit</span><span class="p">(</span><span class="n">ch</span><span class="p">[</span><span class="n">j</span><span class="mi">-1</span><span class="p">]))</span><span class="n">j</span><span class="o">--</span><span class="p">;</span>
<span class="linenos" data-linenos=" 88 "></span>        <span class="kt">int</span> <span class="n">type</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span>
<span class="linenos" data-linenos=" 89 "></span>        <span class="k">if</span><span class="p">(</span><span class="n">ch</span><span class="p">[</span><span class="n">j</span><span class="mi">-1</span><span class="p">]</span><span class="o">==</span><span class="sc">&#39;-&#39;</span><span class="p">)</span><span class="n">type</span><span class="o">=</span><span class="mi">-1</span><span class="p">;</span>
<span class="linenos" data-linenos=" 90 "></span>        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">w</span><span class="o">=</span><span class="n">i</span><span class="p">;</span><span class="n">w</span><span class="o">&gt;=</span><span class="n">j</span><span class="p">;</span><span class="n">w</span><span class="o">--</span><span class="p">)</span>
<span class="linenos" data-linenos=" 91 "></span>            <span class="n">a</span><span class="p">[</span><span class="o">++</span><span class="n">tot</span><span class="p">]</span><span class="o">=</span><span class="n">num</span><span class="p">(</span><span class="n">ch</span><span class="p">[</span><span class="n">w</span><span class="p">]</span><span class="o">-</span><span class="sc">&#39;0&#39;</span><span class="p">,</span><span class="n">i</span><span class="o">-</span><span class="n">w</span><span class="p">,</span><span class="n">type</span><span class="p">);</span>
<span class="linenos" data-linenos=" 92 "></span>        <span class="k">if</span><span class="p">(</span><span class="n">ch</span><span class="p">[</span><span class="n">j</span><span class="mi">-1</span><span class="p">]</span><span class="o">==</span><span class="sc">&#39;+&#39;</span><span class="o">||</span><span class="n">ch</span><span class="p">[</span><span class="n">j</span><span class="mi">-1</span><span class="p">]</span><span class="o">==</span><span class="sc">&#39;-&#39;</span><span class="p">)</span><span class="n">j</span><span class="o">--</span><span class="p">;</span>
<span class="linenos" data-linenos=" 93 "></span>    <span class="p">}</span> 
<span class="linenos" data-linenos=" 94 "></span>    <span class="c1">//for(int i=1;i&lt;=tot;i++)</span>
<span class="linenos" data-linenos=" 95 "></span>    <span class="c1">//  printf(&quot;%d*%d &quot;,a[i].get(),a[i].des);</span>
<span class="linenos" data-linenos=" 96 "></span>    <span class="n">check</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">tot</span><span class="p">);</span>
<span class="linenos" data-linenos=" 97 "></span>    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;=</span><span class="n">tot</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="linenos" data-linenos=" 98 "></span>        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o">&lt;</span><span class="mi">8</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span><span class="c1">//枚举拿走的火柴</span>
<span class="linenos" data-linenos=" 99 "></span>            <span class="k">if</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">check</span><span class="p">(</span><span class="n">j</span><span class="p">))</span>
<span class="linenos" data-linenos="100 "></span>                <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">w</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">w</span><span class="o">&lt;=</span><span class="n">tot</span><span class="p">;</span><span class="n">w</span><span class="o">++</span><span class="p">)</span>
<span class="linenos" data-linenos="101 "></span>                    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">k</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">k</span><span class="o">&lt;</span><span class="mi">8</span><span class="p">;</span><span class="n">k</span><span class="o">++</span><span class="p">)</span>
<span class="linenos" data-linenos="102 "></span>                        <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="n">a</span><span class="p">[</span><span class="n">w</span><span class="p">].</span><span class="n">check</span><span class="p">(</span><span class="n">k</span><span class="p">)){</span>
<span class="linenos" data-linenos="103 "></span>                            <span class="c1">//将i的j放到w的k上</span>
<span class="linenos" data-linenos="104 "></span>                            <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">change</span><span class="p">(</span><span class="n">j</span><span class="p">);</span>
<span class="linenos" data-linenos="105 "></span>                            <span class="n">a</span><span class="p">[</span><span class="n">w</span><span class="p">].</span><span class="n">change</span><span class="p">(</span><span class="n">k</span><span class="p">);</span>
<span class="linenos" data-linenos="106 "></span>                            <span class="k">if</span><span class="p">(</span><span class="n">check</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">tot</span><span class="p">)){</span>
<span class="linenos" data-linenos="107 "></span>                                <span class="kt">int</span> <span class="n">p</span><span class="o">=</span><span class="n">tot</span><span class="p">;</span>
<span class="linenos" data-linenos="108 "></span>                                <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;=</span><span class="n">len</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="linenos" data-linenos="109 "></span>                                    <span class="k">if</span><span class="p">(</span><span class="n">isdigit</span><span class="p">(</span><span class="n">ch</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span><span class="n">putchar</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">p</span><span class="o">--</span><span class="p">].</span><span class="n">get</span><span class="p">()</span><span class="o">+</span><span class="sc">&#39;0&#39;</span><span class="p">);</span>
<span class="linenos" data-linenos="110 "></span>                                    <span class="k">else</span> <span class="n">putchar</span><span class="p">(</span><span class="n">ch</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="linenos" data-linenos="111 "></span>                                <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="linenos" data-linenos="112 "></span>                            <span class="p">}</span> 
<span class="linenos" data-linenos="113 "></span>                            <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">change</span><span class="p">(</span><span class="n">j</span><span class="p">);</span>
<span class="linenos" data-linenos="114 "></span>                            <span class="n">a</span><span class="p">[</span><span class="n">w</span><span class="p">].</span><span class="n">change</span><span class="p">(</span><span class="n">k</span><span class="p">);</span>
<span class="linenos" data-linenos="115 "></span>                        <span class="p">}</span>
<span class="linenos" data-linenos="116 "></span>    <span class="n">printf</span><span class="p">(</span><span class="s">&quot;No&quot;</span><span class="p">);</span> 
<span class="linenos" data-linenos="117 "></span>    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="linenos" data-linenos="118 "></span><span class="p">}</span>
</code></pre></div>
<p><del>跑得慢了点但能过就对了</del></p>
			</div>
			<div class="panel panel-default card" style="padding: 10px;height: 50px;font-size: 20px;">
				<a style="float: left;" href="\article\P4016.html"><i class="fa fa-angle-double-left"></i></a><a style="float: right;" href="\article\CF877E.html"><i class="fa fa-angle-double-right"></i></a>
			</div>
			<div class="panel panel-default card" style="padding: 10px;font-size: 20px;" id="vcomments">
				
			</div>
			<script>
				new Valine({
					el: '#vcomments',
					appId: 'PAlFUPg0pQVTFTEo8gCB4BCf-gzGzoHsz',
					appKey: 'U38ejnLUiizJ6vLyp6ql4hRq',
					path: window.location.pathname
				})
			</script>
		</div>
		<div class="col-md-3">
				<div class="panel panel-default card">
				<div class="panel-heading">
					<h3 class="panel-title">
						<i class="fa fa-info"></i>&emsp;
						<strong>文章信息</strong>
					</h3>
				</div>
                <div style="margin: 10px;">
                    <div style="margin-top: 8px;display: flex;"> 
    <span style="flex: 1 0 auto;margin-right: 6px;">标题</span>
    <span><font style="font-weight: bold">题解 P2702 【[NOI2003]木棒游戏】</font></span>
	</div><div style="margin-top: 8px;display: flex;"> 
    <span style="flex: 1 0 auto;margin-right: 6px;">日期</span>
    <span>2020-07-04 17:57:00</span>
	</div>
                </div>
				</div>
				<div class="panel panel-default card">
				<div class="panel-heading">
					<h3 class="panel-title">
						<i class="fa fa-tag"></i>&emsp;
						<strong>标签</strong>
					</h3>
				</div>
				<div style="margin: 10px;">
					<a href="/tags/2020/" class="tag"><span  style="background-color: rgb(52, 152, 219);">2020</span></a>&nbsp;<a href="/tags/模拟/" class="tag"><span  style="background-color: rgb(231, 76, 60);">模拟</span></a>&nbsp;<a href="/tags/题解/" class="tag"><span  style="background-color: rgb(82, 196, 26);">题解</span></a>
				</div>
				</div>
				
			<div class="panel panel-default card">
					<div class="panel-heading">
						<h3 class="panel-title">
							<i class="fa fa-user-circle-o"></i>&emsp;
							<strong>caijicjl</strong>
						</h3>
					</div>
					<div style="width: 60%;display: inline-block;padding-top: 10px;">
						<ul class="propertyLinks" style="list-style-type: none;">
							<li>
								<img style="vertical-align:middle;position:relative;top:-2px" src="/img/rating-16x16.png">
								Rating:&nbsp;
								<span style="font-weight:bold;color: gray ">312</span>
							</li>
							<li>
								<img style="vertical-align:middle;position:relative;top:-2px" src="/img/star_blue_16.png">
								Contribution:&nbsp;
								<span style="color:gray;font-weight:bold;">0</span>
							</li>
						</ul>
						<ul class="nav-links">
							<li><a href="/settings/">Settings</a></li>
							<li><a href="/archives/">Blog</a></li>
							<li><a href="/teams">Teams</a></li>
							<li><a href="/submissions/dingdingsb">Submissions</a></li>
							<li><a href="/usertalk">Talks</a></li>
							<li><a href="/contests/with/dingdingsb">Contests</a></li>
						</ul>
					</div>
					<div style="display:inline-block;vertical-align: top;margin: 10px;text-align: center;">
						<div style="height:50px;width:50px"><img src="/img/avatar.png"/></div>
						<div><a href="https://www.luogu.com.cn/user/174304" style="font-weight:bold;color:gray">caijicjl</a></div>
					</div>
				</div>
		<div class="panel panel-default card">
				<div class="panel-heading">
					<h3 class="panel-title">
						<i class="fa fa-external-link"></i>&emsp;
						<strong>画中画</strong>
					</h3>
				</div>
				<div style="width:100%;margin:10px">
				<input type="text" id="url"/>
				<input value="创建" type="button" onclick="creat('kk')" /> 
				</div>
		</div>
		<script src="/js/hitokoto.js"></script>
							

				
				<span id="kk"></span>
				<div  id="myScrollspy" class="card" style="width: 100%;"  data-spy="affix">
					<script src="/js/make_toc.js"></script>
				</div>
		</div>
	</div>
 </div>
</body>
</html>
